package com.ten.system.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ten.common.core.entity.AclPermission;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author ：Q大侠
 * @date ：Created in 2022/12/1 22:27
 * @description：
 * @modified By：
 * @version:
 */
public interface AclPermissionDao extends BaseMapper<AclPermission> {
    /** 
     * @create by:  Q大侠
     * @description: 查询权限-无mapper文件 
     * @create time: 2022/12/1 22:38
      * @param userid 
     * @return List<AclPermission>
     */
    @Select(value = "select p.* from acl_permission p join acl_role_permission rp on p.id=rp.permission_id " +
            "join acl_user_role ur on ur.role_id=rp.role_id where ur.user_id=#{userid}")
    List<AclPermission> selectByUserid(String userid);

    /** 
     * @create by:  Q大侠
     * @description:  根据用户名查询具有的权限。
     * @create time: 2022/12/4 6:16
      * @param username
     * @return  
     */
    @Select(value = "select p.* from acl_permission p join acl_role_permission rp on p.id=rp.permission_id " +
            "join acl_user_role ur on ur.role_id=rp.role_id join acl_user u on ur.user_id=u.id " +
            "where u.username=#{username} and p.type=1")
    List<AclPermission> selectByUsername(String username);
    /**
     * 根据角色id查询对于的权限id
     * @param roleId
     * @return
     */
    @Select(value="select distinct permission_id from acl_role_permission where role_id=#{roleId}")
    List<String> selectByRoleId(String roleId);
    /**
     * 根据角色id查询对于的权限id
     * @param
     * @return
    */
    @Select(value="select * from acl_permission where role_id=#{roleId}")
    List<AclPermission> selectLimit(Integer currentPage, Integer pageSize);

}
